from django.contrib.auth.models import AbstractUser
from django.db import models


# Create your models here.
class Course(models.Model):
    id=models.CharField(
        max_length=30,primary_key=True,
        verbose_name="课程编号"
    )
    course_name = models.CharField(
        max_length=100, null=False, verbose_name="课程名称"
    )
    price = models.DecimalField(
        max_digits=7, decimal_places=2,
        null=False, default=0.00, verbose_name="价格",
    )
    course_len_time = models.IntegerField(
        default=0, verbose_name="课程时长"
    )
    course_life_time = models.IntegerField(
        default=0, verbose_name="有效期"
    )
    course_detail = models.CharField(
        max_length=500, verbose_name="课程详情")
    course_class = models.CharField(max_length=10, verbose_name="课程类型")

    def __str__(self):
        return f"{self.course_name}-{self.price}-{self.course_len_time}-{self.course_life_time}"

    class Meta:
        verbose_name = "课程"

class Student(models.Model):
    username = models.CharField(
        max_length=30, primary_key=True,
        verbose_name="用户名"
    )
    password = models.CharField(
        max_length=32, null=False,
        verbose_name="密码"
    )
    student_name = models.CharField(
        max_length=20, verbose_name="姓名"
    )
    sex = models.CharField(
        max_length=2,verbose_name="性别"
    )
    age = models.IntegerField(
        verbose_name="年龄"
    )
    phone = models.CharField(
        max_length=11, verbose_name="手机号"
    )
    email = models.EmailField(
        verbose_name="邮箱"
    )
    course = models.ManyToManyField(Course, through="Order")

    def __str__(self):
        return self.student_name

    class Meta:
        verbose_name = "用户"

class Order(models.Model):
    course=models.ForeignKey(
        Course,on_delete=models.CASCADE
    )
    student=models.ForeignKey(
        Student,on_delete=models.CASCADE
    )
    market_price=models.DecimalField(
        max_digits=7,decimal_places=2,
        verbose_name="零售价"
    )
    buy_time=models.DateTimeField(
        auto_now=True,verbose_name="购买时间"
    )
    def __str__(self):
        return f"{self.student}-{self.course}"

    class Meta:
        verbose_name = "订单"

class Evaluate(models.Model):
    course=models.ForeignKey(
        Course,on_delete=models.CASCADE
    )
    student=models.ForeignKey(
        Student,on_delete=models.CASCADE
    )
    evaluate_time=models.DateTimeField(
        auto_now=True, verbose_name="评价时间"
    )
    content=models.CharField(
        max_length=500,verbose_name="评价内容"
    )
    def __str__(self):
        return f"{self.student}-{self.content}"

    class Meta:
        verbose_name = "评价"

class Outline(models.Model):
    name1=models.CharField(max_length=100, verbose_name="大纲1")
    name2=models.CharField(max_length=100, verbose_name="大纲2")
    name3=models.CharField(max_length=100, verbose_name="大纲3")
    name4=models.CharField(max_length=100, verbose_name="大纲4")
    name5=models.CharField(max_length=100, verbose_name="大纲5")
    course=models.OneToOneField(Course,on_delete=models.CASCADE)

